/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-02-10
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-03-13
 * @Description: 
 */
import 'package:chat_client/providers/individual_provider.dart';
import 'package:chat_client/widgets/captcha.dart';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '/widgets/custom_global_widgets.dart';
import 'asistant_page.dart';

//  用于移动端的设置
class MobilesSettingPage extends StatelessWidget {
  const MobilesSettingPage({super.key});
  @override
  Widget build(BuildContext context) {
    return Consumer<IndividualProvider>(builder: (context, model, child) {
      return Scaffold(
          appBar: AppBar(title: const Text('设置')),
          body: ListView(
            children: [
              CListTile(
                icon: Icons.sync_alt,
                iconColor: Color.fromARGB(255, 90, 140, 255),
                title: '添加我的方式',
                trailing: Icon(Icons.chevron_right),
                onTap: () => model.navToWidget(UpdateByOption(
                  oldInfo: model.user.addType,
                  type: 'addType',
                  title: '修改添加我的方式',
                  widgetIndex: 2,
                )),
              ),
              DividerWithText(
                  height: 10, thickness: 10, indent: 0, endIndent: 0),
              CListTile(
                icon: Icons.lock_reset,
                iconColor: Color.fromARGB(255, 139, 100, 212),
                title: '修改密码',
                trailing: Icon(Icons.chevron_right),
                onTap: () => model.navToWidget(MobileUpdatePaaswordPage()),
              ),
              DividerWithText(
                  height: 10, thickness: 10, indent: 0, endIndent: 0),
              CListTile(
                icon: Icons.person_remove,
                iconColor: Color.fromARGB(255, 236, 67, 67),
                title: '注销账号',
                trailing: Icon(Icons.chevron_right),
                onTap: () => model.navToWidget(MobileLogoutPage()),
              ),
              DividerWithText(
                  height: 10, thickness: 10, indent: 0, endIndent: 0),
              CListTile(
                icon: Icons.logout,
                iconColor: Color.fromARGB(255, 224, 246, 32),
                title: '退出登录',
                onTap: () {
                  BottomMenu.showBottomMenu(
                    context,
                    [
                      BottomMenuItem(
                          title: "确认",
                          icon: Icons.photo_library,
                          onTap: () {
                            model.logout();
                            Navigator.pop(context);
                          }),
                    ],
                  );
                },
              ),
              DividerWithText(height: 0),
            ],
          ));
    });
  }
}

//  用户账号注销页面
class MobileLogoutPage extends StatelessWidget {
  const MobileLogoutPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('注销账号')),
      body: Consumer<IndividualProvider>(builder: (context, model, child) {
        return ListView(
          padding: EdgeInsets.all(40),
          children: [
            const SizedBox(height: 20),
            InputField(
              controller: model.captchaController,
              maxLength: 6,
              icon: Icons.safety_check,
              hintText: '验证码',
              rightSlot:
                  Captcha(onCaptchaUidChanged: model.handleCaptchaUidChanged),
              simplified: true,
            ),
            const SizedBox(height: 40),
            InputField(
              controller: model.passwordController,
              icon: Icons.lock,
              hintText: '密码',
              isPassword: true,
              simplified: true,
            ),
            DividerWithText(height: 2),
            const SizedBox(height: 40),
            ElevatedButton(
              onPressed: () => model.deleteUser(),
              child: const Text('注销'),
            ),
          ],
        );
      }),
    );
  }
}

// 密码修改页面
class MobileUpdatePaaswordPage extends StatelessWidget {
  const MobileUpdatePaaswordPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('修改密码')),
      body: Consumer<IndividualProvider>(builder: (context, model, child) {
        return ListView(
          padding: EdgeInsets.all(40),
          children: [
            const SizedBox(height: 20),
            InputField(
              controller: model.captchaController,
              maxLength: 6,
              icon: Icons.safety_check,
              hintText: '验证码',
              rightSlot:
                  Captcha(onCaptchaUidChanged: model.handleCaptchaUidChanged),
              simplified: true,
            ),
            const SizedBox(height: 40),
            InputField(
              controller: model.oldPasswordController,
              icon: Icons.lock,
              hintText: '旧密码',
              isPassword: true,
              simplified: true,
            ),
            const SizedBox(height: 40),
            InputField(
              controller: model.passwordController,
              icon: Icons.lock,
              hintText: '新密码',
              isPassword: true,
              simplified: true,
            ),
            const SizedBox(height: 40),
            ElevatedButton(
              onPressed: () => model.passwordUpdate(context),
              child: const Text('注销'),
            ),
          ],
        );
      }),
    );
  }
}
